/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
    
package be.vdabantwerpen.gow.dao;
    
import be.vdabantwerpen.gow.entities.Weight;
import be.vdabantwerpen.gow.entities.actions.Action;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Tim.VandenLangenberg
 * @version 12/06/2013
 */
public class ActionDAOTemp implements ActionDAO {
    private final List<Action> actions = new ArrayList();
    private final List<Weight> weights = new ArrayList();
    
    {
        //TODO: actions & weights toevoegen.
    }
    
    @Override
    public void create(Action action){
        actions.add(action);
    }
    
    @Override
    public Action read(String className){
        for(int i = 0; i < actions.size(); i++){
            Action action = actions.get(i);
            if(action.getClass().getName().equals(className)){
                return action;
            }
        }
        return null;
    }
    
    @Override
    public void update(Action action){
        int index = actions.lastIndexOf(action);
        actions.remove(index);
        actions.add(index, action);
    }
    
    @Override
    public void delete(Action action){
        actions.remove(action);
    }
    
    @Override
    public List<Action> findAll(){
        return actions;
    }
    
    @Override
    public List<Weight> findWeights(){
        return weights;
    }
    
    @Override
    public Weight findWeight(String actionName){
        for(int i = 0; i < weights.size(); i++){
            Weight weight = weights.get(i);
            if(weight.getActionType().equalsIgnoreCase(actionName)){
                return weight;
            }
        }
        return null;
    }
    
    @Override
    public void updateWeight(Weight weight){
        int index = weights.indexOf(weight);
        weights.remove(index);
        weights.add(index, weight);
    }
    
}